import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart';
import 'package:school_safe_teacher/resourse/app_colors.dart';
import 'package:school_safe_teacher/widget/my_widget.dart';


import 'action.dart';
import 'state.dart';

Widget buildView(
    ChangeNickNameState state, Dispatch dispatch, ViewService viewService) {
  return body(
      child: Container(
        color: AppColors.MainBackColor,
        child: Column(
          children: [
            Container(
              padding: EdgeInsets.only(left: 15, right: 15),
              child:
                  noRightIconBar(context: viewService.context, title: "修改昵称"),
              color: Colors.white,
            ),
            Expanded(child: _body(state, dispatch, viewService)),
          ],
        ),
      ),
      context: viewService.context);
}

Widget _body(
    ChangeNickNameState state, Dispatch dispatch, ViewService viewService) {
  return Column(
    children: [
      Container(
        width: MediaQuery.of(viewService.context).size.width,
        padding: EdgeInsets.fromLTRB(24, 10, 24, 10),
        child: Text(
          "请设置2-24个字符，不包括@<>/等无效字符哦～",
          textAlign: TextAlign.start,
          style: TextStyle(
              fontWeight: FontWeight.normal,
              fontSize: 11,
              color: AppColors.smallTextColor),
        ),
      ),
      Container(
        color: Colors.white,
        child: TextField(
          onChanged: (value) {
            state..nickName = value;
            dispatch(ChangeNickNameActionCreator.onAction());
          },
          autofocus: true,
          controller: state.nickNameController,
          style: TextStyle(
              fontWeight: FontWeight.normal,
              fontSize: 15,
              color: AppColors.deepTextColor),
          decoration: InputDecoration(
              contentPadding: const EdgeInsets.all(10.0),
              border: InputBorder.none,
              hintText: "请输入用户昵称",
              isDense: true,
              hintStyle: TextStyle(
                  fontWeight: FontWeight.normal,
                  fontSize: 15,
                  color: AppColors.hintTextColor)),
          textAlign: TextAlign.start,
          textAlignVertical: TextAlignVertical.center,
        ),
      ),
      GestureDetector(
        child: Container(
          height: 45,
          margin: EdgeInsets.fromLTRB(25, 58, 25, 0),
          alignment: Alignment.center,
          width: MediaQuery.of(viewService.context).size.width - 50,
          child: Text(
            "确认",
            style: TextStyle(
                color: state.loginTextColor,
                fontSize: 15,
                fontWeight: FontWeight.normal),
          ),
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(25),
            color: AppColors.editBackgroundColor,
            gradient: LinearGradient(
              begin: Alignment.centerLeft,
              end: Alignment.centerRight,
              colors: [
                state.loginBtnStartColor,
                state.loginBtnEndColor,
              ],
            ),
          ),
        ),
        onTap: () {
          dispatch(ChangeNickNameActionCreator.onChangeNickName());
        },
      ),
    ],
  );
}
